<?php
declare (strict_types = 1);

namespace app\admin\event;

use app\admin\model\Usermodel;
use app\admin\model\Classroom;

class UserLogin{

    protected $userModel;
    protected $classModel;

    public function __construct(Usermodel $userModel)
    {
        $this->userModel = $userModel;
        $this->classModel = new Classroom();
    }

    //修改用户信息
    public function setLoginCount()
    {
        $userInfo = $this->userModel->findDetaiInfoById('*', session('adminUserInfo.uid'));
        $dataArr = [
            'logincount' => $userInfo['logincount'] + 1,
            'logintime'  => date("Y-m-d H:i:s", time())
        ];
        $this->userModel->saveInfo($dataArr, session('adminUserInfo.uid'));

        if(session('adminUserInfo.rid') == 7){
            //代理管理员查询管理教室
            $classroomInfo = $this->classModel->findDetaiInfoByOthers('id', ['agent_uid'=>session('adminUserInfo.uid')]);
            if($classroomInfo)
                foreach($classroomInfo as $val)
                    $classRoomIds[] = $val['id'];

            if($classRoomIds)  session('adminUserInfo.crid', implode(',', $classRoomIds));
        }
    }
}
